<template>
  <div class="app-container home">
    <el-card>
      <el-row :gutter="20">
        <el-col :span="6">
          <div>
            <span >PV(今日 页面访问数)</span>
            <span>{{ pv }}</span>
          </div>
        </el-col>
        <el-col :span="6">
          <div>
            <span>UV(今日 IP访问数)</span>
            <span>{{ uv }}</span>
          </div>
        </el-col>
      </el-row>

      <el-row style="margin-top: 120px">
        <div id="statisticWebsite" style="height:800px;"></div>
      </el-row>
      
    </el-card>
    <el-divider />
  </div>
</template>

<script>
import { getBehavior, getActualBehavior } from "@/api/system/statictisWebsite";

export default {
  name: "Index",
  data() {
    return {
      // 版本号
      version: "1.0.0",
      pv: 0,
      uv: 0
    };
  },
  mounted(){
    var statisticWebsite = this.$echarts.init(document.getElementById('statisticWebsite'))
    getBehavior({day: 30}).then(res => {
        var dates = res.result.dates
        var pvData = res.result.pvData
        var uvData = res.result.uvData
        var option = {
              title: {
                text: 'PV、UV 趋势图'
          },
              tooltip: {
                trigger: 'axis',
                axisPointer: {
                  type: 'cross',
                  label: {
                    backgroundColor: '#6a7985'
                  }
              }
          },
              legend: {
                data: ['PV(页面访问数量)', 'UV(IP访问数量)'
              ]
          },
              toolbox: {
                feature: {
                  saveAsImage: {}
              }
          },
              grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
          },
              xAxis: [
              {
                  type: 'category',
                  boundaryGap: false,
                  data: dates
              }
          ],
              yAxis: [
              {
                  type: 'value'
              }
          ],
              series: [
              {
                  name: 'PV(页面访问数量)',
                  type: 'line',
                  stack: 'Total',
                  areaStyle: {},
                  emphasis: {
                    focus: 'series'
                  },
                  data: pvData
              },
              {
                  name: 'UV(IP访问数量)',
                  type: 'line',
                  stack: 'Total',
                  areaStyle: {},
                  emphasis: {
                    focus: 'series'
                  },
                  data: uvData
              }
          ]
        }
        statisticWebsite.setOption(option)
    })

    getActualBehavior().then(res => {
      this.pv = res.result.pv
      this.uv = res.result.uv
    })

    setInterval(() => {
      getActualBehavior().then(res => {
        this.pv = res.result.pv
        this.uv = res.result.uv
      })
    }, 10000)
  },
  methods: {
    
  },
};
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>

